package uestc.lj.basic.greedy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 会议时间安排问题
 *
 * @Author:Crazlee
 * @Date:2021/11/24
 */
public class Code01_BestArange {
	public static class Program {
		public int start;
		public int end;

		public Program(int start, int end) {
			this.start = start;
			this.end = end;
		}
	}

	/**
	 * 贪心安排会议时间
	 *
	 * @param programs  会议数组
	 * @param timePoint 现在的时间点
	 * @return 能够安排最多的会议数量
	 */
	public static int bestArange(Program[] programs, int timePoint) {
		Arrays.sort(programs, new Comparator<Program>() {
			@Override
			public int compare(Program o1, Program o2) {
				return o1.end - o2.end;
			}
		});
		int result = 0;
		for (int i = 0; i < programs.length; i++) {
			if (timePoint <= programs[i].start) {
				result++;
				timePoint = programs[i].end;
			}
		}
		return result;
	}
}
